package com.future.direction.ui.activity;

import android.content.Intent;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.liaoinstan.springview.container.DefaultFooter;
import com.liaoinstan.springview.container.DefaultHeader;
import com.liaoinstan.springview.widget.SpringView;
import com.future.direction.R;
import com.future.direction.common.Constant;
import com.future.direction.common.util.UIUtil;
import com.future.direction.data.bean.OrderBean;
import com.future.direction.di.component.AppComponent;
import com.future.direction.ui.adapter.OrderAdapter;
import com.future.direction.ui.widget.MyTitleBar;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * Created by zhp on 2019-11-08
 */
public class OrderActivity extends BaseActivity {
    @BindView(R.id.titleBar)
    MyTitleBar titleBar;
    @BindView(R.id.recycle_order)
    RecyclerView recycleOrder;
    @BindView(R.id.springView_order)
    SpringView springViewOrder;
    private List<OrderBean> orderBeans;
    private OrderAdapter orderAdapter;

    @Override
    public int setLayout() {
        return R.layout.activity_order;
    }

    @Override
    public void getExtras() {

    }

    @Override
    public boolean init() {
        backListener(titleBar);
        initRecycle();
        return false;
    }

    @Override
    public void setListener() {

        springViewOrder.setListener(new SpringView.OnFreshListener() {
            @Override
            public void onRefresh() {

            }

            @Override
            public void onLoadmore() {

            }
        });
        orderAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                Intent intent = new Intent(UIUtil.getContext(), OrderDetailsActivity.class);
                startActivity(intent);
            }
        });
    }

    @Override
    public void setupAcitivtyComponent(AppComponent appComponent) {

    }

    private void initRecycle() {
        springViewOrder.setHeader(new DefaultHeader(UIUtil.getContext()));
        springViewOrder.setFooter(new DefaultFooter(UIUtil.getContext()));

        orderBeans = new ArrayList<>();
        orderBeans.add(new OrderBean());
        orderBeans.add(new OrderBean());
        orderBeans.add(new OrderBean());
        orderBeans.add(new OrderBean());
        orderBeans.add(new OrderBean());
        orderBeans.add(new OrderBean());
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(UIUtil.getContext(), LinearLayoutManager.VERTICAL, false);
        recycleOrder.setLayoutManager(linearLayoutManager);
        orderAdapter = new OrderAdapter(R.layout.item_order_list, orderBeans);
        recycleOrder.setAdapter(orderAdapter);
    }

}